package Gui;

import Database.DurationDetailsDB;
import Entity.Duration;
import Entity.DurationDetails;
import Entity.TestRenderer;
import Manager.Manager;
import Model.DurationDetailsTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author CONG
 */
public class DialogDurationDetails extends javax.swing.JDialog {

    /** Creates new form DialogDurationDetails */
    private SystemManager sm;
    private Duration dur;
    private Manager manager;
    private DurationDetailsTableModel modelDurationDetails;
    private DurationDetailsDB dbDurationDetails;
    int flag=0;
    public DialogDurationDetails(SystemManager parent, boolean modal,Duration dur,Manager manager) {
        super(parent, modal);
        this.sm=parent;
        this.dur=dur;
        this.manager=manager;
        initComponents();
        showDurationDetails(dur);
    }
    public void showDurationDetails(Duration dur){
        DurationDetails durde=null;
        
        int accountLoanCode=dur.getAccountLoanCode();
        modelDurationDetails=new DurationDetailsTableModel(manager);
        dbDurationDetails=new DurationDetailsDB();
        if(flag!=accountLoanCode){
            
            modelDurationDetails.getDurationDetailsList(dbDurationDetails.getDurationDetailsList(accountLoanCode));
            flag=accountLoanCode;
            tblDurationDetails.setModel(modelDurationDetails);
            TableColumnModel tcm=tblDurationDetails.getColumnModel();
            TableColumn tc=tcm.getColumn(modelDurationDetails.findColumn("Finished"));
            tc.setCellRenderer(new TestRenderer());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnCancel = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblDurationDetails = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setPreferredSize(new java.awt.Dimension(614, 64));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 102, 255));
        jLabel1.setText("Duration Details");
        jPanel1.add(jLabel1);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

        jPanel2.setPreferredSize(new java.awt.Dimension(614, 64));

        btnCancel.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnCancel.setForeground(new java.awt.Color(44, 44, 44));
        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/delete-16x16.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(263, 263, 263)
                .addComponent(btnCancel)
                .addContainerGap(260, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(btnCancel)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_END);

        tblDurationDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblDurationDetails);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**
     * Cancel dialog duration details
     * @param evt 
     */
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
    this.dispose();
}//GEN-LAST:event_btnCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblDurationDetails;
    // End of variables declaration//GEN-END:variables
}
